//
//  NSString+md5String.m
//  cartercoin
//
//  Created by tohier-mac1 on 16/8/24.
//  Copyright © 2016年 tohier-mac1. All rights reserved.
//

#import "NSString+md5String.h"
#import <CommonCrypto/CommonDigest.h>

@implementation NSString (md5String)

+ (NSString *)md5String:(NSString *)str

{
    
    const char *myPasswd = [str UTF8String];
    
    unsigned char mdc[16];
    
    CC_MD5(myPasswd, (CC_LONG)strlen(myPasswd), mdc);
    
    NSMutableString *md5String = [NSMutableString string];
    
    for (int i = 0; i< 16; i++)
    {
        
        [md5String appendFormat:@"%02x",mdc[i]];
        
    }
    
    return md5String;
    
}

/** md5 NB(牛逼的意思)加密*/

+ (NSString *)md5StringNB:(NSString *)str

{
    
    const char *myPasswd = [str UTF8String];
    
    unsigned char mdc[16];
    
    CC_MD5(myPasswd, (CC_LONG)strlen(myPasswd), mdc);
    
    NSMutableString *md5String = [NSMutableString string];
    
    [md5String appendFormat:@"%02x",mdc[0]];
    
    for (int i = 1; i< 16; i++) {
        
        [md5String appendFormat:@"%02x",mdc[i]^mdc[0]];
        
    }
    
    return md5String;
    
}

@end
